package com.caseprocessing.integration;

import com.caseprocessing.enhanced.ComplianceModels.AIComplianceResult;
import com.caseprocessing.model.CaseDocument;
import com.caseprocessing.model.DocumentSegment;

import java.time.LocalDateTime;
import java.util.List;
import java.util.Map;

/**
 * 系统集成相关的数据模型
 */
public class IntegrationModels {
    
    /**
     * 完整处理结果
     */
    public static class CompleteProcessingResult {
        private String processingId;
        private CaseDocument caseDocument;
        private LocalDateTime startTime;
        private LocalDateTime endTime;
        private boolean success;
        private String errorMessage;
        
        private PreprocessingResult preprocessingResult;
        private List<DocumentSegment> documentSegments;
        private List<AIComplianceResult> complianceResults;
        private QualityAssessmentResult qualityAssessment;
        private ProcessingReport processingReport;
        
        public CompleteProcessingResult() {}
        
        // Getters and setters
        public String getProcessingId() { return processingId; }
        public void setProcessingId(String processingId) { this.processingId = processingId; }
        
        public CaseDocument getCaseDocument() { return caseDocument; }
        public void setCaseDocument(CaseDocument caseDocument) { this.caseDocument = caseDocument; }
        
        public LocalDateTime getStartTime() { return startTime; }
        public void setStartTime(LocalDateTime startTime) { this.startTime = startTime; }
        
        public LocalDateTime getEndTime() { return endTime; }
        public void setEndTime(LocalDateTime endTime) { this.endTime = endTime; }
        
        public boolean isSuccess() { return success; }
        public void setSuccess(boolean success) { this.success = success; }
        
        public String getErrorMessage() { return errorMessage; }
        public void setErrorMessage(String errorMessage) { this.errorMessage = errorMessage; }
        
        public PreprocessingResult getPreprocessingResult() { return preprocessingResult; }
        public void setPreprocessingResult(PreprocessingResult preprocessingResult) { this.preprocessingResult = preprocessingResult; }
        
        public List<DocumentSegment> getDocumentSegments() { return documentSegments; }
        public void setDocumentSegments(List<DocumentSegment> documentSegments) { this.documentSegments = documentSegments; }
        
        public List<AIComplianceResult> getComplianceResults() { return complianceResults; }
        public void setComplianceResults(List<AIComplianceResult> complianceResults) { this.complianceResults = complianceResults; }
        
        public QualityAssessmentResult getQualityAssessment() { return qualityAssessment; }
        public void setQualityAssessment(QualityAssessmentResult qualityAssessment) { this.qualityAssessment = qualityAssessment; }
        
        public ProcessingReport getProcessingReport() { return processingReport; }
        public void setProcessingReport(ProcessingReport processingReport) { this.processingReport = processingReport; }
    }
    
    /**
     * 处理选项
     */
    public static class ProcessingOptions {
        private boolean enableAIEnhancement;
        private boolean enableQualityCheck;
        private boolean enableRealTimeMonitoring;
        private boolean generateDetailedReport;
        private int maxProcessingTimeSeconds;
        private String processingPriority; // HIGH, NORMAL, LOW
        private Map<String, Object> customParameters;
        
        public ProcessingOptions() {
            this.enableAIEnhancement = true;
            this.enableQualityCheck = true;
            this.enableRealTimeMonitoring = false;
            this.generateDetailedReport = true;
            this.maxProcessingTimeSeconds = 300; // 5分钟
            this.processingPriority = "NORMAL";
        }
        
        // Getters and setters
        public boolean isEnableAIEnhancement() { return enableAIEnhancement; }
        public void setEnableAIEnhancement(boolean enableAIEnhancement) { this.enableAIEnhancement = enableAIEnhancement; }
        
        public boolean isEnableQualityCheck() { return enableQualityCheck; }
        public void setEnableQualityCheck(boolean enableQualityCheck) { this.enableQualityCheck = enableQualityCheck; }
        
        public boolean isEnableRealTimeMonitoring() { return enableRealTimeMonitoring; }
        public void setEnableRealTimeMonitoring(boolean enableRealTimeMonitoring) { this.enableRealTimeMonitoring = enableRealTimeMonitoring; }
        
        public boolean isGenerateDetailedReport() { return generateDetailedReport; }
        public void setGenerateDetailedReport(boolean generateDetailedReport) { this.generateDetailedReport = generateDetailedReport; }
        
        public int getMaxProcessingTimeSeconds() { return maxProcessingTimeSeconds; }
        public void setMaxProcessingTimeSeconds(int maxProcessingTimeSeconds) { this.maxProcessingTimeSeconds = maxProcessingTimeSeconds; }
        
        public String getProcessingPriority() { return processingPriority; }
        public void setProcessingPriority(String processingPriority) { this.processingPriority = processingPriority; }
        
        public Map<String, Object> getCustomParameters() { return customParameters; }
        public void setCustomParameters(Map<String, Object> customParameters) { this.customParameters = customParameters; }
    }
    
    /**
     * 预处理结果
     */
    public static class PreprocessingResult {
        private boolean valid;
        private List<String> issues;
        private Map<String, Object> metadata;
        private LocalDateTime preprocessingTime;
        
        public PreprocessingResult() {
            this.preprocessingTime = LocalDateTime.now();
        }
        
        // Getters and setters
        public boolean isValid() { return valid; }
        public void setValid(boolean valid) { this.valid = valid; }
        
        public List<String> getIssues() { return issues; }
        public void setIssues(List<String> issues) { this.issues = issues; }
        
        public Map<String, Object> getMetadata() { return metadata; }
        public void setMetadata(Map<String, Object> metadata) { this.metadata = metadata; }
        
        public LocalDateTime getPreprocessingTime() { return preprocessingTime; }
    }
    
    /**
     * 质量评估结果
     */
    public static class QualityAssessmentResult {
        private double splittingQualityScore;
        private double complianceQualityScore;
        private double overallQualityScore;
        private String qualityLevel;
        private List<String> qualityIssues;
        private List<String> qualityRecommendations;
        
        public QualityAssessmentResult() {}
        
        // Getters and setters
        public double getSplittingQualityScore() { return splittingQualityScore; }
        public void setSplittingQualityScore(double splittingQualityScore) { this.splittingQualityScore = splittingQualityScore; }
        
        public double getComplianceQualityScore() { return complianceQualityScore; }
        public void setComplianceQualityScore(double complianceQualityScore) { this.complianceQualityScore = complianceQualityScore; }
        
        public double getOverallQualityScore() { return overallQualityScore; }
        public void setOverallQualityScore(double overallQualityScore) { this.overallQualityScore = overallQualityScore; }
        
        public String getQualityLevel() { return qualityLevel; }
        public void setQualityLevel(String qualityLevel) { this.qualityLevel = qualityLevel; }
        
        public List<String> getQualityIssues() { return qualityIssues; }
        public void setQualityIssues(List<String> qualityIssues) { this.qualityIssues = qualityIssues; }
        
        public List<String> getQualityRecommendations() { return qualityRecommendations; }
        public void setQualityRecommendations(List<String> qualityRecommendations) { this.qualityRecommendations = qualityRecommendations; }
    }
    
    /**
     * 处理报告
     */
    public static class ProcessingReport {
        private String reportId;
        private LocalDateTime generationTime;
        private int totalPages;
        private int segmentCount;
        private long processingTimeMs;
        private String overallQuality;
        private double qualityScore;
        private int highRiskIssues;
        private List<String> keyFindings;
        private List<String> recommendations;
        
        public ProcessingReport() {
            this.generationTime = LocalDateTime.now();
        }
        
        // Getters and setters
        public String getReportId() { return reportId; }
        public void setReportId(String reportId) { this.reportId = reportId; }
        
        public LocalDateTime getGenerationTime() { return generationTime; }
        public void setGenerationTime(LocalDateTime generationTime) { this.generationTime = generationTime; }
        
        public int getTotalPages() { return totalPages; }
        public void setTotalPages(int totalPages) { this.totalPages = totalPages; }
        
        public int getSegmentCount() { return segmentCount; }
        public void setSegmentCount(int segmentCount) { this.segmentCount = segmentCount; }
        
        public long getProcessingTimeMs() { return processingTimeMs; }
        public void setProcessingTimeMs(long processingTimeMs) { this.processingTimeMs = processingTimeMs; }
        
        public String getOverallQuality() { return overallQuality; }
        public void setOverallQuality(String overallQuality) { this.overallQuality = overallQuality; }
        
        public double getQualityScore() { return qualityScore; }
        public void setQualityScore(double qualityScore) { this.qualityScore = qualityScore; }
        
        public int getHighRiskIssues() { return highRiskIssues; }
        public void setHighRiskIssues(int highRiskIssues) { this.highRiskIssues = highRiskIssues; }
        
        public List<String> getKeyFindings() { return keyFindings; }
        public void setKeyFindings(List<String> keyFindings) { this.keyFindings = keyFindings; }
        
        public List<String> getRecommendations() { return recommendations; }
        public void setRecommendations(List<String> recommendations) { this.recommendations = recommendations; }
    }
    
    /**
     * 批量处理选项
     */
    public static class BatchProcessingOptions {
        private int batchSize;
        private int maxConcurrency;
        private boolean enableProgressTracking;
        private boolean enableFailureRecovery;
        private int retryAttempts;
        private long delayBetweenBatchesMs;
        
        public BatchProcessingOptions() {
            this.batchSize = 10;
            this.maxConcurrency = 3;
            this.enableProgressTracking = true;
            this.enableFailureRecovery = true;
            this.retryAttempts = 2;
            this.delayBetweenBatchesMs = 1000;
        }
        
        // Getters and setters
        public int getBatchSize() { return batchSize; }
        public void setBatchSize(int batchSize) { this.batchSize = batchSize; }
        
        public int getMaxConcurrency() { return maxConcurrency; }
        public void setMaxConcurrency(int maxConcurrency) { this.maxConcurrency = maxConcurrency; }
        
        public boolean isEnableProgressTracking() { return enableProgressTracking; }
        public void setEnableProgressTracking(boolean enableProgressTracking) { this.enableProgressTracking = enableProgressTracking; }
        
        public boolean isEnableFailureRecovery() { return enableFailureRecovery; }
        public void setEnableFailureRecovery(boolean enableFailureRecovery) { this.enableFailureRecovery = enableFailureRecovery; }
        
        public int getRetryAttempts() { return retryAttempts; }
        public void setRetryAttempts(int retryAttempts) { this.retryAttempts = retryAttempts; }
        
        public long getDelayBetweenBatchesMs() { return delayBetweenBatchesMs; }
        public void setDelayBetweenBatchesMs(long delayBetweenBatchesMs) { this.delayBetweenBatchesMs = delayBetweenBatchesMs; }
    }
    
    /**
     * 批量处理结果
     */
    public static class BatchProcessingResult {
        private String batchId;
        private LocalDateTime startTime;
        private LocalDateTime endTime;
        private int totalDocuments;
        private int successCount;
        private int failureCount;
        private List<CompleteProcessingResult> results;
        private BatchStatistics statistics;
        
        public BatchProcessingResult() {}
        
        // Getters and setters
        public String getBatchId() { return batchId; }
        public void setBatchId(String batchId) { this.batchId = batchId; }
        
        public LocalDateTime getStartTime() { return startTime; }
        public void setStartTime(LocalDateTime startTime) { this.startTime = startTime; }
        
        public LocalDateTime getEndTime() { return endTime; }
        public void setEndTime(LocalDateTime endTime) { this.endTime = endTime; }
        
        public int getTotalDocuments() { return totalDocuments; }
        public void setTotalDocuments(int totalDocuments) { this.totalDocuments = totalDocuments; }
        
        public int getSuccessCount() { return successCount; }
        public void setSuccessCount(int successCount) { this.successCount = successCount; }
        
        public int getFailureCount() { return failureCount; }
        public void setFailureCount(int failureCount) { this.failureCount = failureCount; }
        
        public List<CompleteProcessingResult> getResults() { return results; }
        public void setResults(List<CompleteProcessingResult> results) { this.results = results; }
        
        public BatchStatistics getStatistics() { return statistics; }
        public void setStatistics(BatchStatistics statistics) { this.statistics = statistics; }
    }
    
    /**
     * 批量统计
     */
    public static class BatchStatistics {
        private double averageProcessingTime;
        private double successRate;
        private double averageQualityScore;
        private Map<String, Integer> documentTypeDistribution;
        private Map<String, Integer> issueTypeDistribution;
        
        public BatchStatistics() {}
        
        // Getters and setters
        public double getAverageProcessingTime() { return averageProcessingTime; }
        public void setAverageProcessingTime(double averageProcessingTime) { this.averageProcessingTime = averageProcessingTime; }
        
        public double getSuccessRate() { return successRate; }
        public void setSuccessRate(double successRate) { this.successRate = successRate; }
        
        public double getAverageQualityScore() { return averageQualityScore; }
        public void setAverageQualityScore(double averageQualityScore) { this.averageQualityScore = averageQualityScore; }
        
        public Map<String, Integer> getDocumentTypeDistribution() { return documentTypeDistribution; }
        public void setDocumentTypeDistribution(Map<String, Integer> documentTypeDistribution) { this.documentTypeDistribution = documentTypeDistribution; }
        
        public Map<String, Integer> getIssueTypeDistribution() { return issueTypeDistribution; }
        public void setIssueTypeDistribution(Map<String, Integer> issueTypeDistribution) { this.issueTypeDistribution = issueTypeDistribution; }
    }
    
    /**
     * 系统健康报告
     */
    public static class SystemHealthReport {
        private LocalDateTime checkTime;
        private HealthStatus overallHealth;
        private boolean apiConnected;
        private Map<String, ComponentHealth> componentHealth;
        private List<String> healthIssues;
        private List<String> recommendations;
        
        public SystemHealthReport() {}
        
        // Getters and setters
        public LocalDateTime getCheckTime() { return checkTime; }
        public void setCheckTime(LocalDateTime checkTime) { this.checkTime = checkTime; }
        
        public HealthStatus getOverallHealth() { return overallHealth; }
        public void setOverallHealth(HealthStatus overallHealth) { this.overallHealth = overallHealth; }
        
        public boolean isApiConnected() { return apiConnected; }
        public void setApiConnected(boolean apiConnected) { this.apiConnected = apiConnected; }
        
        public Map<String, ComponentHealth> getComponentHealth() { return componentHealth; }
        public void setComponentHealth(Map<String, ComponentHealth> componentHealth) { this.componentHealth = componentHealth; }
        
        public List<String> getHealthIssues() { return healthIssues; }
        public void setHealthIssues(List<String> healthIssues) { this.healthIssues = healthIssues; }
        
        public List<String> getRecommendations() { return recommendations; }
        public void setRecommendations(List<String> recommendations) { this.recommendations = recommendations; }
    }
    
    /**
     * 健康状态
     */
    public enum HealthStatus {
        HEALTHY("健康"),
        DEGRADED("降级"),
        UNHEALTHY("不健康");
        
        private final String description;
        
        HealthStatus(String description) {
            this.description = description;
        }
        
        public String getDescription() { return description; }
    }
    
    /**
     * 组件健康状态
     */
    public static class ComponentHealth {
        private String componentName;
        private HealthStatus status;
        private String message;
        private LocalDateTime lastCheckTime;
        
        public ComponentHealth(String componentName, HealthStatus status) {
            this.componentName = componentName;
            this.status = status;
            this.lastCheckTime = LocalDateTime.now();
        }
        
        public ComponentHealth(String componentName, HealthStatus status, String message) {
            this(componentName, status);
            this.message = message;
        }
        
        // Getters and setters
        public String getComponentName() { return componentName; }
        public HealthStatus getStatus() { return status; }
        public String getMessage() { return message; }
        public LocalDateTime getLastCheckTime() { return lastCheckTime; }
    }
    
    /**
     * 性能优化结果
     */
    public static class PerformanceOptimizationResult {
        private LocalDateTime optimizationTime;
        private List<OptimizationAction> optimizationActions;
        private double expectedImprovement;
        private String optimizationSummary;
        
        public PerformanceOptimizationResult() {}
        
        // Getters and setters
        public LocalDateTime getOptimizationTime() { return optimizationTime; }
        public void setOptimizationTime(LocalDateTime optimizationTime) { this.optimizationTime = optimizationTime; }
        
        public List<OptimizationAction> getOptimizationActions() { return optimizationActions; }
        public void setOptimizationActions(List<OptimizationAction> optimizationActions) { this.optimizationActions = optimizationActions; }
        
        public double getExpectedImprovement() { return expectedImprovement; }
        public void setExpectedImprovement(double expectedImprovement) { this.expectedImprovement = expectedImprovement; }
        
        public String getOptimizationSummary() { return optimizationSummary; }
        public void setOptimizationSummary(String optimizationSummary) { this.optimizationSummary = optimizationSummary; }
    }
    
    /**
     * 优化行动
     */
    public static class OptimizationAction {
        private String actionType;
        private String description;
        private Map<String, Object> parameters;
        private double expectedImpact;
        
        public OptimizationAction(String actionType, String description) {
            this.actionType = actionType;
            this.description = description;
        }
        
        // Getters and setters
        public String getActionType() { return actionType; }
        public void setActionType(String actionType) { this.actionType = actionType; }
        
        public String getDescription() { return description; }
        public void setDescription(String description) { this.description = description; }
        
        public Map<String, Object> getParameters() { return parameters; }
        public void setParameters(Map<String, Object> parameters) { this.parameters = parameters; }
        
        public double getExpectedImpact() { return expectedImpact; }
        public void setExpectedImpact(double expectedImpact) { this.expectedImpact = expectedImpact; }
    }
    
    /**
     * 性能指标
     */
    public static class PerformanceMetrics {
        private double averageProcessingTime;
        private double errorRate;
        private double memoryUsage;
        private double cpuUsage;
        private int activeConnections;
        private LocalDateTime lastUpdated;
        
        public PerformanceMetrics() {
            this.lastUpdated = LocalDateTime.now();
        }
        
        // Getters and setters
        public double getAverageProcessingTime() { return averageProcessingTime; }
        public void setAverageProcessingTime(double averageProcessingTime) { this.averageProcessingTime = averageProcessingTime; }
        
        public double getErrorRate() { return errorRate; }
        public void setErrorRate(double errorRate) { this.errorRate = errorRate; }
        
        public double getMemoryUsage() { return memoryUsage; }
        public void setMemoryUsage(double memoryUsage) { this.memoryUsage = memoryUsage; }
        
        public double getCpuUsage() { return cpuUsage; }
        public void setCpuUsage(double cpuUsage) { this.cpuUsage = cpuUsage; }
        
        public int getActiveConnections() { return activeConnections; }
        public void setActiveConnections(int activeConnections) { this.activeConnections = activeConnections; }
        
        public LocalDateTime getLastUpdated() { return lastUpdated; }
        public void setLastUpdated(LocalDateTime lastUpdated) { this.lastUpdated = lastUpdated; }
    }
    
    /**
     * 系统性能监控器
     */
    public static class SystemPerformanceMonitor {
        private final Map<String, Long> processingTimes;
        private final Map<String, CompleteProcessingResult> processingResults;
        private PerformanceMetrics currentMetrics;
        
        public SystemPerformanceMonitor() {
            this.processingTimes = new java.util.concurrent.ConcurrentHashMap<>();
            this.processingResults = new java.util.concurrent.ConcurrentHashMap<>();
            this.currentMetrics = new PerformanceMetrics();
        }
        
        public void recordProcessingStart(String processingId, CaseDocument document) {
            processingTimes.put(processingId, System.currentTimeMillis());
        }
        
        public void recordProcessingComplete(String processingId, long processingTimeMs, CompleteProcessingResult result) {
            processingResults.put(processingId, result);
            updateMetrics();
        }
        
        public void recordProcessingError(String processingId, Exception error) {
            // 记录错误信息
            updateMetrics();
        }
        
        public PerformanceMetrics getCurrentMetrics() {
            return currentMetrics;
        }
        
        public void collectMetrics() {
            // 收集系统指标
            updateMetrics();
        }
        
        private void updateMetrics() {
            // 更新性能指标
            currentMetrics.setLastUpdated(LocalDateTime.now());
        }
    }
    
    /**
     * 系统健康检查器
     */
    public static class SystemHealthChecker {
        
        public SystemHealthReport checkSystemHealth() {
            SystemHealthReport report = new SystemHealthReport();
            report.setCheckTime(LocalDateTime.now());
            
            // 简化的健康检查实现
            report.setOverallHealth(HealthStatus.HEALTHY);
            report.setApiConnected(true);
            
            return report;
        }
    }
    
    /**
     * 系统配置
     */
    public static class SystemConfiguration {
        private long maxAcceptableProcessingTime;
        private double maxAcceptableErrorRate;
        private double maxAcceptableMemoryUsage;
        private Map<String, Object> advancedSettings;
        
        public SystemConfiguration() {
            this.maxAcceptableProcessingTime = 300000; // 5分钟
            this.maxAcceptableErrorRate = 0.05; // 5%
            this.maxAcceptableMemoryUsage = 0.8; // 80%
            this.advancedSettings = new HashMap<>();
        }
        
        // Getters and setters
        public long getMaxAcceptableProcessingTime() { return maxAcceptableProcessingTime; }
        public void setMaxAcceptableProcessingTime(long maxAcceptableProcessingTime) { this.maxAcceptableProcessingTime = maxAcceptableProcessingTime; }
        
        public double getMaxAcceptableErrorRate() { return maxAcceptableErrorRate; }
        public void setMaxAcceptableErrorRate(double maxAcceptableErrorRate) { this.maxAcceptableErrorRate = maxAcceptableErrorRate; }
        
        public double getMaxAcceptableMemoryUsage() { return maxAcceptableMemoryUsage; }
        public void setMaxAcceptableMemoryUsage(double maxAcceptableMemoryUsage) { this.maxAcceptableMemoryUsage = maxAcceptableMemoryUsage; }
        
        public Map<String, Object> getAdvancedSettings() { return advancedSettings; }
        public void setAdvancedSettings(Map<String, Object> advancedSettings) { this.advancedSettings = advancedSettings; }
    }
}